<template>
    <!-- 我的资产 -->
    <div class="youke">
        <Navs left></Navs>
        <Main>
            <van-cell-group class="field-box">
                <van-field
                        :value="$store.getters.zhichans.cjf"
                        center
                        clearable
                        label="可用资产"
                        :readonly="true"
                >
                    <van-button :disabled="true" slot="button" size="small" class="readonly">枚</van-button>
                </van-field>
            </van-cell-group>
            <van-cell-group class="field-box">
                <!-- <van-field v-model="rmbad" center clearable placeholder="请输入或者粘贴转出的" label="钱包地址"/> -->
                <van-field v-model="mobile" center clearable placeholder="请输入对方手机号" label="对方手机号"/>
            </van-cell-group>
            <van-cell-group class="field-box">
                <van-row class="all">
                    <van-col span="19">
                        <van-field v-model="amount" type="number" center clearable placeholder="请输入数量"
                                   label="转出数量"></van-field>
                    </van-col>
                    <van-col span="2">
                        <span>枚</span>
                    </van-col>
                    <van-col span="3">
                        <van-tag plain type="primary" @click="allfun">全部</van-tag>
                    </van-col>
                </van-row>
                <van-field
                        v-model="password"
                        type="password"
                        center
                        clearable
                        placeholder="请输入交易密码"
                        label="交易密码"
                />
            </van-cell-group>
            <!-- <van-cell-group>
              <van-field v-model="yzm" type="number" center clearable label="短信验证码" placeholder="请输入短信验证码">
                <van-button slot="button" size="small" type="primary" @click="getCode">{{mobilesendText}}</van-button>
              </van-field>
            </van-cell-group> -->
            <div class="footer">
                <van-button class="post" type="info" @click="save" :disabled="disable">提交</van-button>
            </div>
        </Main>
        <!-- <Tabbar></Tabbar> -->
    </div>
</template>

<script type="text/ecmascript-6">
    import {user, sms, games} from "@/api";

    export default {
        //接收父级传递的参数
        props: [],
        //监听数据变化
        watch: {},
        data() {
            return {
                sms: "",
                rmbad: "",
                mobile: "",
                amount: "",
                password: "",
                yzm: "",
                mobilesend: true,
                mobilesendText: "发送验证码",
                times: null,
                timesText: 60,
                disable: false,

            };
        },
        //实例初始化之前触发事件
        beforeCreate() {
        },
        //实例化之后触发事件
        created() {
        },
        //实时监控data参数数据变化
        computed: {},
        //模板组件
        components: {},
        //执行方法
        methods: {
            save() {
                let data = {
                    rmbad: this.rmbad,
                    tel: this.mobile,
                    jf: this.amount,
                    passwo: this.password,
                    yzm: this.yzm,
                };
                // if (this.rmbad == "") {
                //   this.$toast.fail("钱包地址不能为空");
                //   return false;
                // }
                if (this.mobile == "") {
                    this.$toast.fail("对方手机号码");
                    return false;
                }
                if (this.amount == "") {
                    this.$toast.fail("请输入数量");
                    return false;
                }
                if (this.password == "") {
                    this.$toast.fail("请输入交易密码");
                    return false;
                }
                this.disable = true;
                user.zczz(data).then(res => {
                    if (res.code == 1000) {
                        let that = this;
                        that.$store.dispatch("addinfo");
                        that.$toast({
                            forbidClick: true,
                            message: res.reason,
                        });
                        setTimeout(function () {
                            that.$router.push({path:'/user'});
                        }, 2900);
                    } else {
                        this.disable = false;

                    }
                }).catch(res => {
                    this.disable = false;

                });
            },
            getCode() {
                if (this.mobilesend) {
                    this.mobilesend = false;
                    sms
                        .code()
                        .then(res => {
                            if (res.code == 1000) {
                                this.timesfun();
                            } else {
                                this.mobilesend = true;
                                this.$toast.fail(res.reason);
                            }
                        })
                        .catch(err => {
                        });
                }
            },
            allfun() {
                this.amount = this.$store.getters.zhichans.cjf;
            },
            timesfun() {
                let self = this;
                self.mobilesendText = `重新获取(${self.timesText}s)`;
                let times = setInterval(function () {
                    self.timesText--;
                    self.mobilesendText = `重新获取(${self.timesText}s)`;
                    if (self.timesText <= 0) {
                        self.mobilesend = true;
                        self.mobilesendText = "发送验证码";
                        self.timesText = 60;
                        window.clearInterval(times);
                    }
                }, 1000);
            }
        },
        mounted() {
            this.$store.dispatch("addzhichan")
        }
        //路由退出时候调用
    };
</script>

<style scoped lang="less">
    .field-box {
        margin-bottom: 0.5rem;
    }

    .all {
        line-height: 3rem;
        left: 15px;
        /*border-bottom: 1px solid #F4F4F4;*/
    }

    .readonly {
        border: none;
    }

    .footer {
        width: 94%;
        margin: 1rem auto;

        .post {
            width: 100%;
            border-radius: 0.2rem;
        }
    }

    .van-cell:not(:last-child)::after {
        /*left: 0px;*/
    }
</style>
